﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;

public partial class CustomerManagement_CREDIT : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["FCode"] = "300400114";
        if (!IsPostBack)
        {
            txtCustomerCode.Attributes.Add("onclick", "SearchVIP('../');");

            drpType.Items.Add(new ListItem("全部", "-1"));
            List<Model.CREDITTYPE> types= new BLL.CREDITTYPE().GetAllList();
            foreach (Model.CREDITTYPE type in types)
            {
                drpType.Items.Add(new ListItem(type.CREDITTYPE_NAME, type.CREDITTYPE_ID.ToString()));
            }

            AspNetPager1.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["RowCountPerPage"].ToString());
            Bind();
        }

    }

    private void Bind()
    {
        StringBuilder Sql = new StringBuilder();
        
        Sql.Append(this.txtBillId.Text.Trim() == "" ? "" : " and CREDIT_ID='" + this.txtBillId.Text.Trim() + "'");
        Sql.Append(this.drpType.SelectedValue == "-1" ? "" : " and CREDIT_TYPE='" + this.drpType.SelectedItem.Value + "'");
        Sql.Append(this.txtCustomerCode.Text.Trim() == "" ? "" : " and CREDIT_CUSTOMERCODE like'%" + this.txtCustomerCode.Text.Trim() + "%'");
        Sql.Append(this.txtCheckDateStart.Text.Trim() == "" ? "" : " and CREDIT_ADDTIME>='" + this.txtCheckDateStart.Text.Trim() + "'");
        Sql.Append(this.txtCheckDateEnd.Text.Trim() == "" ? "" : " and CREDIT_ADDTIME<='" + this.txtCheckDateEnd.Text.Trim() + " 23:59:59.999'");
            
        int pageCount, rowCount;
        List<Model.CREDIT> credits = new BLL.CREDIT().GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, "CREDIT_ID", false, Sql.ToString(), out pageCount, out rowCount);
        CREDITListControl1.Bind(credits);
        AspNetPager1.RecordCount = rowCount;
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 1;
        Bind();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (true)//Check.CheckPermission("200300104", "00001")
        {
            Response.Redirect("CREDITEDIT.aspx");
        }
        else
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Bind();
    }
}
